package com.naiterui.ehp.bs.patient.dao.impl;

import com.naiterui.ehp.bp.domain.DrChargeConfig;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.utils.lang.StringUtil;
import com.naiterui.ehp.bs.patient.dao.IDrMessageConsultChargeDao;
import com.naiterui.ehp.bs.patient.feign.IDoctorFeignClient;
import com.naiterui.ehp.bs.patient.repository.IApDrMessageConsultChargeRepository;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 医生图文咨询收费持久层
 *
 * @author guoyongxiang
 * @since 2.7.0
 */
@Component
@RequiredArgsConstructor
public class ApDrMessageConsultChargeDaoImpl implements IDrMessageConsultChargeDao {

    private final IApDrMessageConsultChargeRepository drMessageConsultChargeRepository;
    private final IDoctorFeignClient doctorFeignClient;

    /**
     * @param patientId
     * @param doctorId
     *
     * @return
     *
     * @Author guoyongxiang
     * @Date 2017年3月31日
     * @see com.naiterui.ehp.bs.patient.dao.IDrMessageConsultChargeDao#getChargeById(java.lang.Long,
     * java.lang.Long)
     * @since 2.7.0
     */
    @Override
    public Integer getChargeById(Long doctorId, Long patientId) {
        /*
        List<DrMessageConsultCharge> chargeList = drMessageConsultChargeRepository.findByChargePKDoctorIdAndChargePKPatientId(doctorId, patientId);
        if (chargeList != null && !chargeList.isEmpty()) {
            return chargeList.get(0).getCharge();
        }
        return 0;
        */
        // 医生服务费设置
        Map<Long,Integer> chargeMap = doctorFeignClient.doctorCharge(doctorId + "", DrChargeConfig.TYPE_MESSAGE);
        return chargeMap.getOrDefault(doctorId, 0);
    }

    @Override
    public Integer getChargeById(Long doctorId, Long patientId, Integer type) {
        // 医生服务费设置
        Map<Long,Integer> chargeMap = doctorFeignClient.doctorCharge(doctorId + "", type);
        return chargeMap.getOrDefault(doctorId, 0);
    }

    /**
     * @param patientId
     * @param doctorIds
     *
     * @return
     *
     * @Author guoyongxiang
     * @Date 2017年3月31日
     * @see com.naiterui.ehp.bs.patient.dao.IDrMessageConsultChargeDao#getChargeListByPatientId(java.lang.Long,
     * java.util.List)
     * @since 2.7.0
     */
    @Override
    public Map<Long, Integer> getChargeListByPatientId(Long patientId, List<Long> doctorIds) throws BusinessException {

        String doctorIdStr = StringUtil.convertCollection(doctorIds);
        /*
        List<DrMessageConsultCharge> chargeList = drMessageConsultChargeRepository.findByChargePKPatientIdAndChargePKDoctorIdIn(patientId, doctorIds);

        Map<Long, Integer> doctorMap = new HashMap<>();

        if (chargeList != null && !chargeList.isEmpty()) {
            for (DrMessageConsultCharge charge : chargeList) {
                doctorMap.put(charge.getChargePK().getDoctorId(), charge.getCharge());
            }
        }
        */
        // 医生服务费设置
        Map<Long,Integer> chargeMap = doctorFeignClient.doctorCharge(doctorIdStr, DrChargeConfig.TYPE_MESSAGE);
        return chargeMap;
    }

}
